package com.zsy;

import com.core.jdbc.SqlHelper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class testSend2 {
    public static void main(String[] arg) throws SQLException {

        testShi();
    }

    public static void testShi() {
        try {
            // 发送POST请求
            URL url = new URL("https://tispfile.utourworld.com/upload/op/xml/agentLine/index.xml");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setUseCaches(false);
            conn.setDoOutput(true);

            String postData = "{\n" +
                    "    \"visitCode\":\"CYTS\",\n" +
                    "    \"key\":\"a22748ea2f77906b13d4ed51421dd864\",\n" +
                    "    \"date\":\"2018-11-27 09:47:00\",\n" +
                    "    \"param\":{\n" +
                    "    \t\t\"userCode\":\"AGENT201606230020906\",\n" +
                    "    \t\t\"token\":\"jing123\",\n" +
                    "    \t\t\"objStr\":\"8121C7B933BFA6F20166CE5D6C1BE242\"\n" +
                    "    }\n" +
                    "}";
            conn.setRequestProperty("Content-Length", "" + postData.length());
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            out.write(postData);
            out.flush();
            out.close();

            // 获取响应状态
            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                System.out.println("ok,200!");
                ;
            }
            // 获取响应内容体
            String line = "";
            String result = "";
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream(), "gbk"));
            while ((line = in.readLine()) != null) {
                result += line + "\n";
            }
            System.out.println(result);
            String jj = Xml2Json.xml2JSON(result);
            in.close();
            System.out.println(jj);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
